package com.frogs.ucenter.controller;

import java.util.Arrays;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import com.alibaba.fastjson.JSONObject;
import com.frogs.framework.base.web.BaseController3;
import com.frogs.framework.util.StringUtil;
import com.frogs.framework.web.HttpRequestInfo;
import com.frogs.system.util.ApiUrlParamEnum;
import com.frogs.ucenter.component.UserPermissionHelper;
import com.frogs.ucenter.entity.UserShippingAddress;
import com.frogs.ucenter.service.AreaService;
import com.frogs.ucenter.service.UserService;

@Controller("areaController")
public class AreaController extends BaseController3 {

	private static Logger log = LoggerFactory.getLogger(AreaController.class);
	
	private static final String POSTCODE_SHOW = "/postcode/show";
	
	@Resource
	private UserPermissionHelper userPermissionHelper;
	
	@Resource
	private AreaService areaService;
	
	@Resource
	private UserService userService;
    
    @RequestMapping(POSTCODE_SHOW)
    public JSONObject showPostCode(HttpServletRequest request,HttpServletResponse response, ModelMap model, UserShippingAddress userShippingAddressNew) throws Exception {
    	try {
    		HttpRequestInfo requestInfo = new HttpRequestInfo(request);
    		
    		String areaId = requestInfo.getParameter(ApiUrlParamEnum.areaCode.getParamName(), null);
    		String address = requestInfo.getParameter(ApiUrlParamEnum.address.getParamName(), null);
    		
    		if(StringUtil.isEmpty(areaId) || StringUtil.isEmpty(address)) {
    			return null;
    		}
    		
    		JSONObject jso = areaService.showPostCode(address, areaId);
    		return jso;
    	} catch (Exception e) {
    		log.error("func[showPostCode] parameterMap[{}] exception[{} - {}] desc[fail]",//
    				new Object[] { request.getParameterMap(), e.getMessage(), Arrays.deepToString(e.getStackTrace()) });
    	}
    	return null;
    }
}